package com.sgb.kjwl.view.ui.adapter.self.logistics;



/*
 *  说明：运输订单 适配器（物流运输  货主）
 * */

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.CarriageManageEntity;
import com.sgb.kjwl.model.entity.self.TransportOrderEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

//临时暂用的  CarriageManageEntity  数据  7月3号（为方便临时用的，不是正式数据）
public class TransportOrderAdater extends BaseRecycleAdapter<TransportOrderEntity> {
    buttonClickListener buttonClickListener;
    public TransportOrderAdater(Context context, List<TransportOrderEntity> datas) {
        super(context, R.layout.item_transport_order, datas);
    }

    public void setButtonClickListener(TransportOrderAdater.buttonClickListener buttonClickListener) {
        this.buttonClickListener = buttonClickListener;
    }

    @Override
    public void convert(ItemViewHolder holder, TransportOrderEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ImageView state_img = holder.getItem().findViewById(R.id.state_img);
        TextView tvCancel=holder.getItem().findViewById(R.id.tv_cancel);
        TextView tvConfirm=holder.getItem().findViewById(R.id.tv_confirm);
        TextView tvDel=holder.getItem().findViewById(R.id.tv_del);
        TextView tvfreight=holder.getItem().findViewById(R.id.tv_freight);
        tvfreight.setText(entity.getFreight()+"元/吨");


        holder.itemView.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 if(buttonClickListener!=null){
                     buttonClickListener.confirm(entity.getOrderNo());
                 }
            }
        });


        holder.itemView.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(buttonClickListener!=null){
                    buttonClickListener.onCancel(entity.getOrderNo());
                }
            }
        });
        tvDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(buttonClickListener!=null){
                    buttonClickListener.onDelete(entity.getOrderNo());
                }
            }
        });
        switch (entity.getStatus()) {
            case "0":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_dqr));
                tvDel.setVisibility(View.GONE);
                tvConfirm.setVisibility(View.VISIBLE);
                tvCancel.setVisibility(View.VISIBLE);
                break;
            case "1":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_dfc));
                tvDel.setVisibility(View.GONE);
                tvConfirm.setVisibility(View.GONE);
                tvCancel.setVisibility(View.GONE);
                break;
            case "2":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_ysz));
                tvDel.setVisibility(View.GONE);
                tvConfirm.setVisibility(View.GONE);
                tvCancel.setVisibility(View.GONE);

                break;
            case "3":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_ywc));
                tvDel.setVisibility(View.GONE);
                tvConfirm.setVisibility(View.GONE);
                tvCancel.setVisibility(View.GONE);
                break;
            case "4":
                state_img.setBackground(context.getResources().getDrawable(R.mipmap.icn_yqx));
                tvDel.setVisibility(View.VISIBLE);
                tvConfirm.setVisibility(View.GONE);
                tvCancel.setVisibility(View.GONE);

                break;
        }




    }

 public  interface buttonClickListener{

    void confirm(String orderNo);

    void onCancel(String orderNo);

    void onDelete(String orderNo);


}



}
